﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using MbUnit.Framework;

namespace Mite.Core.Tests.Domain
{
	[TestFixture]
	public class ColumnTestFixture
	{
		[Test] 
		public void Identity_can_be_set_in_ctor()
		{
			Column column = new Column("name", DbType.Int32, ColumnAttributes.Identity);
			Assert.IsTrue(column.IsIdentity);
		}

		[Test]
		public void PrimaryKey_can_be_set_in_ctor()
		{
			Column column = new Column("name", DbType.Int32, ColumnAttributes.PrimaryKey);
			Assert.IsTrue(column.IsPrimaryKey);
		}

		[Test]
		public void NotNull_can_be_set_in_ctor()
		{
			Column column = new Column("name", DbType.Int32, ColumnAttributes.NotNull);
			Assert.IsFalse(column.IsNullable);
		}

		[Test]
		public void Identity_can_be_set()
		{
			Column column = new Column();
			column.Identity();

			Assert.IsTrue(column.IsIdentity);
		}

		[Test]
		public void PrimaryKey_can_be_set()
		{
			Column column = new Column();
			column.PrimaryKey();

			Assert.IsTrue(column.IsPrimaryKey);
		}

		[Test]
		public void Identity_can_be_removed()
		{
			Column column = new Column("name", DbType.Int32, ColumnAttributes.Identity);
			column.RemoveIdentity();

			Assert.IsFalse(column.IsIdentity, "Could not remove identity attribute.");
		}

		[Test]
		public void PrimaryKey_being_set_makes_column_not_null()
		{
			Column column = new Column();

			Assert.IsTrue(column.IsNullable, "Test precondition failed.  New columns should be nullable by default.");

			column.PrimaryKey();

			Assert.IsFalse(column.IsNullable, "Column that is a primary key should not be nullable.");
		}
	}
}
